package o;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;

public class aix implements aef {
    private d ʻ = this.ʼ;
    private d ʼ = new d(0, this.ˎ);
    private d ʽ = this.ʼ;
    private final o.aiy.c ˊ = new o.aiy.c();
    private long ˊॱ;
    private final alc ˋ;
    private c ˋॱ;
    private final int ˎ;
    private final aiy ˏ = new aiy();
    private long ˏॱ;
    private Format ͺ;
    private final anc ॱ = new anc(32);
    private boolean ॱˊ;
    private boolean ॱॱ;
    private Format ᐝ;

    public interface c {
        void ˎ(Format format);
    }

    static final class d {
        @Nullable
        public d ˊ;
        public final long ˋ;
        public final long ˎ;
        @Nullable
        public aky ˏ;
        public boolean ॱ;

        public d(long j, int i) {
            this.ˋ = j;
            this.ˎ = ((long) i) + j;
        }

        public void ˏ(aky o_aky, d dVar) {
            this.ˏ = o_aky;
            this.ˊ = dVar;
            this.ॱ = true;
        }

        public int ˎ(long j) {
            return ((int) (j - this.ˋ)) + this.ˏ.ˋ;
        }

        public d ˋ() {
            this.ˏ = null;
            d dVar = this.ˊ;
            this.ˊ = null;
            return dVar;
        }
    }

    public aix(alc o_alc) {
        this.ˋ = o_alc;
        this.ˎ = o_alc.ˏ();
    }

    public void ˏ() {
        ˏ(false);
    }

    public void ˏ(boolean z) {
        this.ˏ.ˏ(z);
        ˋ(this.ʼ);
        this.ʼ = new d(0, this.ˎ);
        this.ʻ = this.ʼ;
        this.ʽ = this.ʼ;
        this.ˊॱ = 0;
        this.ˋ.ˋ();
    }

    public int ˋ() {
        return this.ˏ.ˋ();
    }

    public boolean ॱ() {
        return this.ˏ.ॱ();
    }

    public int ˊ() {
        return this.ˏ.ˏ();
    }

    public Format ˎ() {
        return this.ˏ.ˎ();
    }

    public long ॱॱ() {
        return this.ˏ.ˊ();
    }

    public boolean ᐝ() {
        return this.ˏ.ᐝ();
    }

    public void ʻ() {
        this.ˏ.ʽ();
        this.ʻ = this.ʼ;
    }

    public void ॱ(long j, boolean z, boolean z2) {
        ˎ(this.ˏ.ˋ(j, z, z2));
    }

    public void ʽ() {
        ˎ(this.ˏ.ʼ());
    }

    public int ʼ() {
        return this.ˏ.ॱॱ();
    }

    public int ˎ(long j, boolean z, boolean z2) {
        return this.ˏ.ॱ(j, z, z2);
    }

    public int ˋ(abk o_abk, DecoderInputBuffer decoderInputBuffer, boolean z, boolean z2, long j) {
        switch (this.ˏ.ˊ(o_abk, decoderInputBuffer, z, z2, this.ᐝ, this.ˊ)) {
            case -5:
                this.ᐝ = o_abk.ॱ;
                return -5;
            case -4:
                if (!decoderInputBuffer.ˏ()) {
                    if (decoderInputBuffer.ˏ < j) {
                        decoderInputBuffer.ॱ(Integer.MIN_VALUE);
                    }
                    if (decoderInputBuffer.ʻ()) {
                        ˊ(decoderInputBuffer, this.ˊ);
                    }
                    decoderInputBuffer.ˊ(this.ˊ.ॱ);
                    ˋ(this.ˊ.ˋ, decoderInputBuffer.ॱ, this.ˊ.ॱ);
                }
                return -4;
            case -3:
                return -3;
            default:
                throw new IllegalStateException();
        }
    }

    private void ˊ(DecoderInputBuffer decoderInputBuffer, o.aiy.c cVar) {
        long j;
        long j2;
        int i = 1;
        int i2 = 0;
        long j3 = cVar.ˋ;
        this.ॱ.ˏ(1);
        ˊ(j3, this.ॱ.ˏ, 1);
        j3++;
        byte b = this.ॱ.ˏ[0];
        int i3 = (b & DnsConfig.MAX_CACHE_ENTRIES) != 0 ? 1 : 0;
        int i4 = b & 127;
        if (decoderInputBuffer.ˋ.ˊ == null) {
            decoderInputBuffer.ˋ.ˊ = new byte[16];
        }
        ˊ(j3, decoderInputBuffer.ˋ.ˊ, i4);
        j3 += (long) i4;
        if (i3 != 0) {
            this.ॱ.ˏ(2);
            ˊ(j3, this.ॱ.ˏ, 2);
            j3 += 2;
            i = this.ॱ.ॱॱ();
            j = j3;
        } else {
            j = j3;
        }
        int[] iArr = decoderInputBuffer.ˋ.ˏ;
        if (iArr == null || iArr.length < i) {
            iArr = new int[i];
        }
        int[] iArr2 = decoderInputBuffer.ˋ.ˋ;
        if (iArr2 == null || iArr2.length < i) {
            iArr2 = new int[i];
        }
        if (i3 != 0) {
            i3 = i * 6;
            this.ॱ.ˏ(i3);
            ˊ(j, this.ॱ.ˏ, i3);
            j += (long) i3;
            this.ॱ.ˋ(0);
            while (i2 < i) {
                iArr[i2] = this.ॱ.ॱॱ();
                iArr2[i2] = this.ॱ.ʽॱ();
                i2++;
            }
            j2 = j;
        } else {
            iArr[0] = 0;
            iArr2[0] = cVar.ॱ - ((int) (j - cVar.ˋ));
            j2 = j;
        }
        o.aef.d dVar = cVar.ˊ;
        decoderInputBuffer.ˋ.ॱ(i, iArr, iArr2, dVar.ˋ, decoderInputBuffer.ˋ.ˊ, dVar.ˊ, dVar.ˏ, dVar.ॱ);
        i3 = (int) (j2 - cVar.ˋ);
        cVar.ˋ += (long) i3;
        cVar.ॱ -= i3;
    }

    private void ˋ(long j, ByteBuffer byteBuffer, int i) {
        ˏ(j);
        while (i > 0) {
            int min = Math.min(i, (int) (this.ʻ.ˎ - j));
            byteBuffer.put(this.ʻ.ˏ.ˊ, this.ʻ.ˎ(j), min);
            i -= min;
            j += (long) min;
            if (j == this.ʻ.ˎ) {
                this.ʻ = this.ʻ.ˊ;
            }
        }
    }

    private void ˊ(long j, byte[] bArr, int i) {
        ˏ(j);
        int i2 = i;
        while (i2 > 0) {
            int min = Math.min(i2, (int) (this.ʻ.ˎ - j));
            System.arraycopy(this.ʻ.ˏ.ˊ, this.ʻ.ˎ(j), bArr, i - i2, min);
            i2 -= min;
            j += (long) min;
            if (j == this.ʻ.ˎ) {
                this.ʻ = this.ʻ.ˊ;
            }
        }
    }

    private void ˏ(long j) {
        while (j >= this.ʻ.ˎ) {
            this.ʻ = this.ʻ.ˊ;
        }
    }

    private void ˎ(long j) {
        if (j != -1) {
            while (j >= this.ʼ.ˎ) {
                this.ˋ.ˋ(this.ʼ.ˏ);
                this.ʼ = this.ʼ.ˋ();
            }
            if (this.ʻ.ˋ < this.ʼ.ˋ) {
                this.ʻ = this.ʼ;
            }
        }
    }

    public void ॱ(c cVar) {
        this.ˋॱ = cVar;
    }

    public void ˎ(Format format) {
        Format ˊ = ˊ(format, this.ˏॱ);
        boolean ˏ = this.ˏ.ˏ(ˊ);
        this.ͺ = format;
        this.ॱॱ = false;
        if (this.ˋॱ != null && ˏ) {
            this.ˋॱ.ˎ(ˊ);
        }
    }

    public int ˏ(adv o_adv, int i, boolean z) throws IOException, InterruptedException {
        int ˊ = o_adv.ˊ(this.ʽ.ˏ.ˊ, this.ʽ.ˎ(this.ˊॱ), ˎ(i));
        if (ˊ != -1) {
            ˊ(ˊ);
            return ˊ;
        } else if (z) {
            return -1;
        } else {
            throw new EOFException();
        }
    }

    public void ˎ(anc o_anc, int i) {
        while (i > 0) {
            int ˎ = ˎ(i);
            o_anc.ˎ(this.ʽ.ˏ.ˊ, this.ʽ.ˎ(this.ˊॱ), ˎ);
            i -= ˎ;
            ˊ(ˎ);
        }
    }

    public void ˋ(long j, int i, int i2, int i3, @Nullable o.aef.d dVar) {
        if (this.ॱॱ) {
            ˎ(this.ͺ);
        }
        long j2 = j + this.ˏॱ;
        if (this.ॱˊ) {
            if ((i & 1) != 0 && this.ˏ.ˋ(j2)) {
                this.ॱˊ = false;
            } else {
                return;
            }
        }
        this.ˏ.ˊ(j2, i, (this.ˊॱ - ((long) i2)) - ((long) i3), i2, dVar);
    }

    private void ˋ(d dVar) {
        int i = 0;
        if (dVar.ॱ) {
            int i2;
            if (this.ʽ.ॱ) {
                i2 = 1;
            } else {
                i2 = 0;
            }
            aky[] o_akyArr = new aky[(i2 + (((int) (this.ʽ.ˋ - dVar.ˋ)) / this.ˎ))];
            while (i < o_akyArr.length) {
                o_akyArr[i] = dVar.ˏ;
                dVar = dVar.ˋ();
                i++;
            }
            this.ˋ.ˎ(o_akyArr);
        }
    }

    private int ˎ(int i) {
        if (!this.ʽ.ॱ) {
            this.ʽ.ˏ(this.ˋ.ˊ(), new d(this.ʽ.ˎ, this.ˎ));
        }
        return Math.min(i, (int) (this.ʽ.ˎ - this.ˊॱ));
    }

    private void ˊ(int i) {
        this.ˊॱ += (long) i;
        if (this.ˊॱ == this.ʽ.ˎ) {
            this.ʽ = this.ʽ.ˊ;
        }
    }

    private static Format ˊ(Format format, long j) {
        if (format == null) {
            return null;
        }
        if (j == 0 || format.ˊॱ == Long.MAX_VALUE) {
            return format;
        }
        return format.ॱ(format.ˊॱ + j);
    }
}
